//
//  JobCategoryTableViewController.m
//  DIsciplineSelectPartner
//
//  Created by 唐秦崴 on 15/3/19.
//  Copyright (c) 2015年 Lizzy. All rights reserved.
//

#import "JobCategoryTableViewController.h"
#import "JobCategoryTableViewCell.h"

@interface JobCategoryTableViewController ()

@property (nonatomic,copy) NSArray* textLabelMArray; // 这个地方要用NSArray，因为NSMutabelArray不要和copy同时使用
@property (nonatomic,copy) NSArray* imageNameArray_1;
@property (nonatomic,copy) NSArray* imageNameArray_2;

@end

static const int BMOBQUERY_LIMIT = 1000;  // Bmob 单次查询数据数目的上限
static NSString* CellTableIdentifier = @"CellTableIdentifier";  // 这个用于自定义单元格样式

@implementation JobCategoryTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置返回按钮的颜色
    self.navigationController.navigationBar.tintColor = [ UIColor whiteColor ];
    // 设置返回按钮文字
    // Set this in every view controller so that the back button displays back instead of the root view controller name
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    
    // 设置分割线样式
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.tableView.separatorColor = [UIColor colorWithRed:236/255.0 green:208/255.0 blue:191/255.0 alpha:1 ];
    
    /// 添加文字内容
    self.textLabelMArray = @[@"理学",@"工学",@"农学",@"医学",@"哲学",@"经济学",@"管理学",@"法学", @"教育学",@"文学", @"历史学",@"艺术学",@"特殊   职业",@"非限   专业"];
    self.imageNameArray_1 = @[@"lixue_1",@"gongxue_1",@"nongxue_1",@"yixue_1",@"zhexue_1",@"jingji_1",@"guanli_1",@"falv_1", @"jiaoyu_1",@"wenxue_1", @"lishi_1",@"yishu_1",@"teshu_1",@"nolimit_1"];
    self.imageNameArray_2 = @[@"lixue_2",@"gongxue_2",@"nongxue_2",@"yixue_2",@"zhexue_2",@"jingji_2",@"guanli_2",@"falv_2", @"jiaoyu_2",@"wenxue_2", @"lishi_2",@"yishu_2",@"teshu_2",@"nolimit_2"];
    
    // 设置表格的单元格
    self.tableView.rowHeight = 80;
    UINib* nib = [ UINib nibWithNibName:@"JobCategoryTableViewCell" bundle:nil];
    [ self.tableView registerNib:nib forCellReuseIdentifier:@"CellTableIdentifier" ];
    
    UIEdgeInsets contentInset = self.tableView.contentInset;
    contentInset.top = 0;
    [self.tableView  setContentInset:contentInset];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    // Return the number of sections.
//    return 1;
//}

// tableView每个分区的行数，可以为各个分区设置不同的行数，根据section的值判断即可
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [ self.textLabelMArray count ];
}

// 实现每一行Cell的内容，tableView重用机制
static const float CELL_ARROW_X       = 300;
static const float CELL_ARROW_Y       = 30;
static const float CELL_ARROW_HEIGHT  = 20;
static const float CELL_ARROW_WIDTH   = 15;
-(UITableViewCell* ) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    JobCategoryTableViewCell* cell = [ tableView dequeueReusableCellWithIdentifier:CellTableIdentifier forIndexPath:indexPath ];
    cell.name = [self.textLabelMArray objectAtIndex:indexPath.row ];
    cell.imageNameString_1 = [self.imageNameArray_1 objectAtIndex:indexPath.row];
    cell.imageNameString_2 = [self.imageNameArray_2 objectAtIndex:indexPath.row];
    
    // 设置右侧小箭头
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"arrow_right_orange"] forState:UIControlStateNormal];
    [button setFrame:CGRectMake( CELL_ARROW_X , CELL_ARROW_Y, CELL_ARROW_WIDTH, CELL_ARROW_HEIGHT)];
    [cell.contentView addSubview:button];
    
    return cell;
}

// 设置选中某行的处理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if( 0 == indexPath.section )
    {
        NSLog(@"you chosed row: %lu", indexPath.row ); //test
        
        // 清空 大学的数组
//        [ self.universitysForSelectedProvince removeAllObjects ];
//        
//        // Bmob查询
//        BmobQuery   *bquery = [BmobQuery queryWithClassName:@"University"];
//        bquery.limit = BMOBQUERY_LIMIT;
//        [bquery orderByAscending:@"order"];
//        [bquery whereKey:@"province" equalTo: [ self.textLabelMArray objectAtIndex:indexPath.row ]];
//        [bquery findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
//            
//            //            NSLog( @" array count ： %lu", [ array count ] );
//            for (BmobObject *obj in array) {
//                
//                //                NSLog(@"obj.playerName = %@", [obj objectForKey:@"playerName"]);
//                University* university = [[ University alloc ] initWithBmobObject:obj];
//                [ self.universitysForSelectedProvince addObject:university ];
//                
//            }
//            
//            [ self performSegueWithIdentifier:@"provinceUniversity" sender:self ];
//        }];
        
        
    }
    else
    {
        NSLog( @"You chosed section unknown , row： %lu", indexPath.row );
        return ;
    }
    
}

@end
